

<template>
  <view class="Mall4j container">
    <view class="order-detail">
      <!-- 订单状态 -->
      <view class="order-status">
        <view class="status-bg">
          <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/status-bg.png" />
        </view>
        <view class="status-text">{{
            [
              "",
              i18n.waitingBuyerPay,
              i18n.waitingForDelivery,
              i18n.waitingBuyerReceipt,
              i18n.orderCompleted,
              i18n.orderCompleted,
              i18n.orderCancelled,
              i18n.itInaGroup,
            ][status]
          }}</view>
        <view class="step">
          <view :class="[
              'item',
              status == 2 || status == 3 || status == 4 || status == 5
                ? 'active'
                : '',
            ]">
            <view class="select" />
            <view class="des">{{ i18n.buyerPayment }}</view>
          </view>
          <!-- 自提没有这一项 -->
          <view v-if="dvyType == 1" :class="[
              'item',
              dvyType == 1 && (status == 3 || status == 4 || status == 5)
                ? 'active'
                : '',
            ]">
            <view class="select" />
            <view class="des">{{ i18n.merchantShipment }}</view>
          </view>
          <!-- 快递没有这一项 -->
          <view v-if="dvyType == 2" :class="['item', status == 3 || status == 5 ? 'active' : '']">
            <view class="select" />
            <view class="des">{{ i18n.buyerPickUp }}</view>
          </view>
          <view v-if="dvyType == 3" :class="['item', status >= 3 ? 'active' : '']">
            <view class="select" />
            <view class="des">{{ i18n.merchantDelivery }}</view>
          </view>
          <view :class="['item', status == 4 || status == 5 ? 'active' : '']">
            <view class="select" />
            <view class="des">{{ i18n.transactionComplete }}</view>
          </view>
        </view>
      </view>

      <!-- 配送地址 -->
      <view v-if="dvyType != 2 && userAddrDto" class="address-box">
        <view class="img">
          <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/addr.png" />
        </view>
        <view class="user-info">
          <view class="name">{{ userAddrDto.receiver }}</view>
          <view class="phone">{{ userAddrDto.mobile }}</view>
        </view>
        <view class="address-detail">{{ userAddrDto.province }}{{ userAddrDto.city }}{{ userAddrDto.area }}{{ userAddrDto.addr }}</view>
      </view>

      <!-- 地址 -->
      <!-- <view class="delivery-addr">
      <view class="user-info">
        <text class="item">{{userAddrDto.receiver}}</text>
        <text class="item">{{userAddrDto.mobile}}</text>
      </view>
      <view class="addr">{{userAddrDto.province}}{{userAddrDto.city}}{{userAddrDto.area}}{{userAddrDto.area}}{{userAddrDto.addr}}</view>
    </view> -->

      <!-- 自提地址 -->
      <view v-if="dvyType == 2" class="delivery-certificate border_radius_23 mar_20_10">
        <view class="tit"><text v-if="status == 2">{{ i18n.deliveryVoucher }}</text><text v-if="status > 2 || status == 1">{{ i18n.pickup }}</text></view>
        <view class="address">
          <view class="text">{{ stationAddress }}</view>
          <view class="icon-box">
            <view class="icon" @tap="callStation">
              <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/phone.png" />
            </view>
            <view class="bl"></view>
            <view class="icon" @tap="openMap">
              <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/addr.png" />
            </view>
          </view>
        </view>
        <!-- 没付款时 -->
        <view v-if="status == 1" class="code-box ">
          <view class="text-box">
            <view class="item">
              <view class="i-lable">{{ i18n.picker }}：</view>
              <view class="i-text">
                <text>{{ stationUserName }}</text>
                <text>{{ stationUserMobile }}</text>
              </view>
            </view>
          </view>
        </view>
        <!-- 已付款时 -->
        <view v-if="status == 2" class="code-box code-det" @tap="viewCertificate">
          <view class="code">
            <image :src="stationQrCode" />
            <!-- <canvas class="qrcode-img" canvas-id="orderQrcode"></canvas> -->
          </view>
          <view class="text-box">
            <view class="item">
              <view class="i-lable">{{ i18n.pickingCode }}：</view>
              <view class="i-text fw">{{ stationCode }}</view>
            </view>
            <view class="item">
              <view class="i-lable">{{ i18n.picker }}：</view>
              <view class="i-text">
                <text>{{ stationUserName }}</text>
                <text>{{ stationUserMobile }}</text>
              </view>
            </view>
            <view class="item">
              <view class="i-lable">{{ i18n.appointmentTime }}：</view>
              <view class="i-text">{{ stationTime }}</view>
            </view>
          </view>
        </view>
      </view>

      <!-- 商品信息 -->
      <view class="prod-item  ">
        <view class="order-num">
          <view class="order-state">
            <text class="order-sts gray">{{
                [
                  "",
                  i18n.waitingBuyerPay,
                  i18n.waitingForDelivery,
                  i18n.waitingBuyerReceipt,
                  i18n.orderCompleted,
                  i18n.orderCompleted,
                  i18n.orderCancelled,
                  i18n.inAGroup,
                ][status]
              }}</text>
          </view>
        </view>
        <block v-for="(item, index) in orderItemDtos" :key="index">
          <view class="item-cont" :data-prodid="item.prodId" :data-prodstatus="item.prodStatus" @tap="toProdPage">
            <view class="prod-pic">
              <image v-if="item.pic" :src="item.pic" />
              <image v-else src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/def.png" mode="aspectFit" />
            </view>
            <!-- 拼团商品展示icon -->
            <view v-if="orderType == 1 || orderType == 2" class="spell-group-icon">
              <text class="group-text">{{
                  ["", i18n.aGroup, i18n.spike][orderType]
                }}</text>
            </view>
            <view class="prod-info">
              <view class="prodname">{{ item.prodName }}</view>
              <view class="prod-info-cont">
                <text class="number">{{ i18n.quantity }}：{{ item.prodCount }}</text>
                <!-- <text class="info-item">{{item.skuName}}</text> -->
              </view>
              <view class="price-nums">
                <text class="prodprice">
                  <text v-if="item.price" class="symbol">￥</text>
                  <text v-if="item.price" class="big-num">{{
                      wxs.parsePrice(item.price)[0]
                    }}</text>
                  <text v-if="item.price" class="small-num">.{{ wxs.parsePrice(item.price)[1] }}</text>
                </text>
                <!-- <view class='btn-box'>
                <text class='btn'>申请售后</text>
                <text class='btn'>加购物车</text>
              </view> -->
              </view>
            </view>
            <!-- 申请退款btn -->
            <text v-if="!item.refundSn && canRefund && orderType != 3 &&
                (item.actualTotal || (!item.actualTotal && item.useScore > 0))" class="apply-refund-btn" data-refundtype="2" :data-type="status == 2 ? '1' : '2'" @tap.stop="applyRefund(item, 2)">{{ i18n.requestRefund }}</text>
            <text v-if="item.refundSn" class="apply-refund-btn" :data-refundsn="item.refundSn" @tap.stop="viewRefund">{{ i18n.checkRefund }}</text>
            <!-- 申请退款btn -->
          </view>
          <view class="prod-foot">
            <view class="btn">
              <button v-if="item.status == 1" class="button" :data-ordernum="item.primaryOrderNo" hover-class="none" @tap="onCancelOrder">
                {{ i18n.cancelOrder }}
              </button>
              <!-- <button wx:if="{{item.status==1}}" class="button warn" bindtap="onConfirmReceive" data-ordernum="{{item.primaryOrderNo}}" hover-class='none'>再次购买</button> -->
              <button v-if="item.status == 1" class="button warn" :data-ordernum="item.primaryOrderNo" hover-class="none" @tap="onPayAgain">
                {{ i18n.payment }}
              </button>
              <!-- <button v-if="item.status==3 || item.status==5" class="button" @tap="toDeliveryPage" :data-ordernum="item.primaryOrderNo" hover-class="none">{{i18n.viewLogistics}}</button> -->
              <button v-if="item.status == 3" class="button warn" :data-ordernum="item.primaryOrderNo" hover-class="none" @tap="onConfirmReceive">
                {{ i18n.confirmRceipt }}
              </button>
            </view>
          </view>
        </block>
      </view>

      <!-- 订单信息 -->
      <view class="order-msg">
        <view class="msg-item">
          <view class="item">
            <text class="item-tit">{{ i18n.orderNumber }}：</text>
            <text class="item-txt">{{ orderNumber }}</text>
            <!--  #ifdef  APP-PLUS -->
            <text class="copy-btn" @tap="copyBtn">{{ i18n.copy }}</text>
            <!--  #endif -->
          </view>
          <view class="item">
            <text class="item-tit">{{ i18n.orderTime }}：</text>
            <text class="item-txt">{{ createTime }}</text>
          </view>
        </view>
        <view class="msg-item">
          <view v-if="status>1 && payType" class="item">
            <text class="item-tit">{{ i18n.paymentMethod }}：</text>
            <text class="item-txt">{{
                [
                  i18n.integralPayment,
                  i18n.payWithWeChat,
                  i18n.PayWithAli,
                  i18n.payWithWeChat,
                  i18n.payWithWeChat,
                  i18n.payWithWeChat,
                  i18n.PayWithAli,
                  i18n.PayWithAli,
                  i18n.payWithWeChat,
                  i18n.balancePay,
                  i18n.paypalPay
                ][payType]
              }}</text>
          </view>
          <view class="item">
            <text class="item-tit">{{ i18n.deliveryMethod }}：</text>
            <!-- 1卖家配送 2到店自提 3无需快递 4同城配送 -->
            <text class="item-txt">{{
                [
                  "",
                  i18n.sellerDelivery,
                  i18n.pickStore,
                  i18n.noNeedDelivery,
                  i18n.sameDelivery,
                ][dvyType]
              }}</text>
          </view>
          <view v-if="remarks" class="item">
            <text class="item-tit">{{ i18n.OrderNotes }}：</text>
            <text class="item-txt">{{ remarks ? remarks : "" }}</text>
          </view>
        </view>
      </view>

      <view class="order-msg">
        <view class="msg-item">
          <view class="item">
            <view class="item-tit">{{ i18n.comTotal }}：</view>
            <view class="item-txt price">
              <text class="symbol">￥</text>
              <text class="big-num">{{
                  wxs.parsePrice(productTotalAmount)[0]
                }}</text>
              <text class="small-num">.{{ wxs.parsePrice(productTotalAmount)[1] }}</text>
            </view>
          </view>
          <view class="item">
            <view class="item-tit">{{ i18n.shipping }}：</view>
            <view class="item-txt price">
              <text class="symbol">￥</text>
              <text class="big-num">{{ wxs.parsePrice(transfee)[0] }}</text>
              <text class="small-num">.{{ wxs.parsePrice(transfee)[1] }}</text>
            </view>
          </view>
          <view v-if="reduceAmount" class="item">
            <view class="item-tit">{{ i18n.preferential }}：</view>
            <view class="item-txt price">
              <text class="symbol">-￥</text>
              <text class="big-num">{{ wxs.parsePrice(reduceAmount)[0] }}</text>
              <text class="small-num">.{{ wxs.parsePrice(reduceAmount)[1] }}</text>
            </view>
          </view>
          <!--        <view class="item coupon member-points" :data-index="index" v-if="totalUsableScore > 0">
          <view class="integral-wrap">
            <view class="integral-icon"><image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/integral-icon2.png"></image></view>
            <view class="integral-deduction">可用{{totalUsableScore}}积分抵扣{{totalScoreAmount}}元</view>
          </view>
          <view class="integral-right-select">
            <checkbox class="#fbad4d" value="isScorePay" @tap="useMemberPoints" checked="isChecked"></checkbox>
          </view>
        </view> -->
          <view class="item payment">
            <view class="item-txt price">
              <text v-if="actualTotal" class="color_999">{{ i18n.orderTotal }}：</text>
              <text v-if="actualTotal" class="symbol">￥</text>
              <text v-if="actualTotal" class="big-num">{{
                  wxs.parsePrice(actualTotal)[0]
                }}</text>
              <text v-if="actualTotal" class="small-num">.{{ wxs.parsePrice(actualTotal)[1] }}</text>
              <text v-if="actualTotal && (orderType == 3 || orderScore > 0)" class="small-num" decode="true">&ensp;+&ensp;</text>
              <text v-if="orderType == 3 || orderScore > 0" class="big-num">{{ orderScore
                }}<text class="small-num">{{ i18n.integral }}</text></text>
            </view>
          </view>
        </view>
      </view>

      <!-- 底部栏 -->
      <view class="order-detail-footer">
        <view style="display: flex;align-items: center;">
          <view v-if="isShowMore" class="more-text" @tap="handleMore">{{ i18n.more }}</view>
        </view>
        <view class="footer-box">
          <view v-if="!isShowMore" class="apply-service foot-btn" @tap="handleCustomService">{{ i18n.contactCustomerService }}
          </view>
          <view v-if="isViewInvoice&&!isShowMore" class="apply-service foot-btn" @tap="viewIinvoice(orderNumber,orderInvoiceId)">{{ i18n.invoice.viewInvoice }}
          </view>
          <view v-if="isInvoice&&!isShowMore" class="apply-service foot-btn" @tap="showInvoicePopup(shopId ,orderNumber)">{{ i18n.invoice.InvoicingRequest }}
          </view>
          <button v-if="canAllRefund && orderType != 3 && (actualTotal || (!actualTotal && orderScore > 0))" class="apply-service apply-refund-btn refund-full foot-btn" data-refundtype="1" :data-type="status == 2 ? '1' : '2'" @tap.stop="applyRefund(null, 1)">
            {{ i18n.wholeOrderRefund }}
          </button>
          <!-- 【团购按钮】 -->
          <button v-if="orderType == 1 && status > 1" class="apply-service foot-btn" :data-ordernumber="orderNumber" @tap="toGroupDetails">
            {{ i18n.viewGroupDetails }}
          </button>
          <!-- 【团购按钮】 -->
        </view>
      </view>
      <view v-if="showMore" class="popup" :class="{ show: showMore }">
        <view class="more-popup-mask" @tap="closePopup" />
        <view class="more-box">
          <!-- <view class="more-box-mark" /> -->
          <view class="more-popup-text" @tap="handleCustomService">{{ i18n.contactCustomerService }}</view>
          <view v-if="isViewInvoice" class="more-popup-text" @tap="viewIinvoice(orderNumber,orderInvoiceId)">{{ i18n.invoice.viewInvoice }}</view>
          <view v-if="isInvoice" class="more-popup-text" @tap="showInvoicePopup(shopId ,orderNumber)">{{ i18n.invoice.InvoicingRequest }}</view>
        </view>
      </view>
    </view>
    <invoiceEdit v-if="isShowInvoicePopup" :shop-id="invoiceShopId" :order-number="invoiceOrderNumber" @closePopup="closePopup" @getData="getOrderDataList" />
  </view>
</template>

<script module="wxs" lang="wxs" src="../../wxs/number.wxs"></script>

<script>
// pages/order-detail/order-detail.js
var http = require("../../utils/http.js");
var util = require("../../utils/util.js");
var Qr = require("../../utils/wxqrcode");
import invoiceEdit from '../../components/invoice-edit/index.vue'
export default {
  data () {
    return {
      orderItemDtos: [],
      remarks: "",
      actualTotal: 0,
      userAddrDto: null,
      orderNumber: "",
      createTime: "",
      shopId: null,
      status: 0,
      productTotalAmount: '',
      transfee: '',
      reduceAmount: '',
      actualTotal: '',
      prodid: '',
      orderType: 0,
      canRefund: false,
      // 能否退款
      canAllRefund: false, // 能否整单退款
      hasRefundItem: false,
      isLastProd: false,  //最后一款商品
      irrevocable: false,  //不可撤销
      sum: [],  //本单已申请单个退款的商品数组

      dvyType: 1, //配送类型 1:快递 2:自提 3：无需快递
      id: 0, // 自提信息id
      stationAddress: '', // 自提点的地址
      stationCode: '', // 提货码
      stationId: 0, // 自提点id
      stationPhone: '', // 自提点的联系电话
      stationTime: '', // 自提时间(用户下单时选择)
      stationUserMobile: '', // 自提人的手机
      stationUserName: '', // 自提人的名字
      stationQrCode: '', // 提货码二维码
      stationName: '', // 自提点名称

      payType: '', //订单支付类型
      orderScore: 0, // 整单使用积分
      // 当前订单可退金额
      canRefundAmount: 0,
      seckillId: '',
      orderInvoiceId: '',
      invoiceShopId: '',
      isShowInvoicePopup: false,
      invoiceOrderNumber: '', // 当前选择发票的id
      refundStatus: null,
      showMore: false
    };
  },

  components: { invoiceEdit },
  props: {},

  computed: {
    i18n () {
      return this.$t('index')
    },
    isViewInvoice () {
      return ((this.orderInvoiceId && this.status !== 6) ||
        (this.orderInvoiceId && (this.status === 6 && this.refundStatus))) && this.status !== 1 && this.orderType !== 3
    },
    isInvoice () {
      return !this.orderInvoiceId && this.status !== 6 && this.status !== 1 && this.orderType !== 3
    },
    isShowMore () {
      return (this.isViewInvoice || this.isInvoice) && this.canAllRefund && this.orderType != 3 && this.orderType == 1 && this.status > 1 && this.status !== 6
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.loadOrderDetail(options.orderNum);
    this.orderNumber = options.orderNum
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 加载导航标题
    uni.setNavigationBarTitle({
      title: this.i18n.orderDetails
    });
    this.loadOrderDetail(this.orderNumber);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () { },
  methods: {
    showInvoicePopup (shopId, invoiceOrderNumber) {
      this.invoiceShopId = shopId
      this.invoiceOrderNumber = invoiceOrderNumber
      this.isShowInvoicePopup = true
      this.showMore = false
    },
    handleMore () {
      this.showMore = true
    },
    // 关闭弹窗
    closePopup () {
      this.isShowInvoicePopup = false
      this.showMore = false
    },
    getOrderDataList () {
      this.loadOrderDetail(this.orderNumber);
    },
    // 查看发票
    viewIinvoice (orderNumber, orderInvoiceId) {
      uni.navigateTo({
        url: `/pages/invoice-detail/invoice-detail?orderNumber=${orderNumber}&orderInvoiceId=${orderInvoiceId}`
      })
    },
    //跳转商品详情页
    toProdPage: function (e) {
      util.tapLog(3)
      var prodid = e.currentTarget.dataset.prodid;
      var prodstatus = e.currentTarget.dataset.prodstatus;
      if (Number(prodstatus) !== 1) {
        uni.showToast({
          title: this.i18n.prodRemovedRemoved,
          icon: "none",
          duration: 1000,
        })
        return
      }
      if (this.orderType == 3) {
        this.$Router.push({ path: '/package-member-integral/pages/convert-prod-det/convert-prod-det', query: { prodId: prodid } })
      } else if (this.orderType == 2) {
        if (this.seckillId) {
          this.$Router.push({ path: '/package-activities/pages/snap-up-detail/snap-up-detail', query: { seckillId: this.seckillId } })
        } else {
          uni.showToast({
            title: this.i18n.secondKillClosed,
            icon: "none",
            duration: 1000,
          })
        }
      } else {
        this.$Router.push({ path: '/pages/prod/prod', query: { prodid: prodid } })
      }
    },
    /**
     * 咨询客服
     */
    handleCustomService () {
      console.log(this.shopId);
      util.checkAuthInfo(() => {
        uni.navigateTo({
          url: '/pages/chat/chat?orderNumber=' + this.orderNumber
        });
      })
    },

    /**
     * 是否最后一个商品在执行单个商品退款事件
     */
    lastProdApplyRefund: function () {
      if (this.status == 2) { //待发货状态下
        if (this.orderItemDtos.length > 1) {  //如果商品列表长度大于1
          let sum = 0
          for (let i = 0; i < this.orderItemDtos.length; i++) {
            const element = this.orderItemDtos[i];
            if (element.refundSn) {
              sum += 1
            }
          }
          this.isLastProd = sum === this.orderItemDtos.length - 1
          this.irrevocable = sum === this.orderItemDtos.length
        }
      }
    },

    /**
     * 申请退款
     */
    applyRefund: util.throttle(function (item, refundtype) {
      util.tapLog(3)
      // refundType 退款类型 1整单  2单个物品
      let status = this.status
      var type = this.status == 2 ? '1' : '2'
      this.loadOrderDetail(this.orderNumber)  //请求订单详情数据
      if (refundtype == 1) { //整单退款
        var items = {}
        items.orderNumber = this.orderNumber;
        items.actualTotal = this.actualTotal; // 订单总额
        items.transfee = this.transfee; // 订单运费
        items.status = this.status; // 订单状态
        items.orderItemDtos = this.orderItemDtos;
        items.orderScore = this.orderScore  // 整单积分
        items.buyerMobile = this.dvyType === 2 ? this.stationUserMobile : this.userAddrDto ? this.userAddrDto.mobile : ''
        items.canRefundAmount = this.canRefundAmount
        // 将数据存储到本地
        wx.setStorageSync("refundItem", items);
      } else if (refundtype == 2) { //单个商品退款
        this.lastProdApplyRefund() //是否最后一个商品执行单个商品退款
        if (this.orderItemDtos.length == 1) { // 是否只有一件商品
          item.isOnlyProd = true
        } else {
          item.isOnlyProd = false
        }
        item.orderNumber = this.orderNumber;
        item.transfee = this.transfee; // 本单运费
        item.status = this.status; //订单状态
        item.isLastProd = this.isLastProd ? this.isLastProd : undefined // 是否最后一款商品
        item.canRefundAmount = this.canRefundAmount
        item.buyerMobile = this.dvyType === 2 ? this.stationUserMobile : this.userAddrDto ? this.userAddrDto.mobile : ''
        // 将数据存储到本地
        wx.setStorageSync("refundItem", item);
      }
      /**  判断跳转页面（根据订单是否已发货）*/
      if (status == 2) {   //待发货，直接跳转到申请页，不需要选择退货方式
        uni.navigateTo({ //通过uni.redirectTo实现跳转（关闭当前页面，跳转到应用内某个页面）
          url: `/pages/apply-refund/apply-refund?type=${type}&refundType=${refundtype}`,
        })
      } else {  //已发货，跳转到选择退货方式页
        uni.navigateTo({
          url: '/pages/choose-refund-way/choose-refund-way?refundType=' + refundtype
        })
      }
    }, 600),

    /**
     * 查看退款
     */
    viewRefund: function (e) {
      util.tapLog(3)
      var refundSn = e.currentTarget.dataset.refundsn;
      this.lastProdApplyRefund() //是否最后一个商品执行单个商品退款
      uni.navigateTo({
        url: '/pages/refund-details/refund-details?refundSn=' + refundSn + '&irrevocable=' + this.irrevocable
      })
    },

    /**
     * 加载订单数据
     */
    loadOrderDetail: function (orderNum) {
      var ths = this;
      var params = {
        url: "/p/myOrder/orderDetail",
        method: "GET",
        data: {
          orderNumber: orderNum
        },
        callBack: function (res) {
          ths.setData({
            shopId: res.shopId,
            orderNumber: orderNum,
            actualTotal: res.actualTotal,
            //实际支付总额（商品总额+运费)
            userAddrDto: res.userAddrDto,
            remarks: res.remarks,
            orderItemDtos: res.orderItemDtos,
            createTime: res.createTime,
            status: res.status,
            productTotalAmount: res.total,
            //所有商品总额
            transfee: res.transfee,
            //运费
            reduceAmount: res.reduceAmount,
            orderType: res.orderType,
            shopName: res.shopName,
            canRefund: res.canRefund,
            canAllRefund: res.canAllRefund,
            payType: res.payType,
            orderScore: res.orderScore, // 整单使用积分
            dvyType: res.dvyType, // 配送类型 1:快递 2:自提 3：无需快递
            // 当前订单可退款金额
            canRefundAmount: res.canRefundAmount,
            seckillId: res.seckillId,
            orderInvoiceId: res.orderInvoiceId,
            refundStatus: res.refundStatus
          });
          if (res.dvyType == 2) {
            ths.loadStationDetail(orderNum)
          }
        }
      };
      http.request(params);
    },

    /**
     * 加载订单详情自提信息
     */
    loadStationDetail: function (orderNum) {
      var params = {
        url: "/p/myStationOrder/stationDetail",
        method: "GET",
        data: {
          orderNumber: orderNum
        },
        callBack: (res) => {
          this.id = res.id, // 自提信息id
            this.stationAddress = res.stationAddress, // 自提点的地址
            this.stationCode = res.stationCode, // 提货码
            this.stationId = res.stationId, // 自提点id
            this.stationPhone = res.stationPhone, // 自提点的联系电话
            this.stationTime = res.stationTime, // 自提时间(用户下单时选择)
            this.stationUserMobile = res.stationUserMobile, // 自提人的手机
            this.stationUserName = res.stationUserName, // 自提人的名字
            this.stationName = res.stationName, // 自提点名称
            this.lat = this.bMapTransQQMap(res.lng, res.lat).lat, // 纬度
            this.lng = this.bMapTransQQMap(res.lng, res.lat).lng, // 经度
            this.getQrcode(this.stationCode)
        }
      };
      http.request(params);
    },

    /**
     * 拨打自提点电话
     */
    callStation: function () {
      util.tapLog(3)
      uni.makePhoneCall({
        // 手机号
        phoneNumber: this.stationPhone,
        // 成功回调
        success: (res) => {
          console.log(res)
        },
        // 失败回调
        fail: (res) => {
          console.log(res)
        }
      });
    },

    // 将百度地图经纬度转换为腾讯/高德地图经纬度
    bMapTransQQMap: function (lng, lat) {
      let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
      let x = lng - 0.0065;
      let y = lat - 0.006;
      let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
      let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
      let lngs = z * Math.cos(theta);
      let lats = z * Math.sin(theta);
      return {
        lng: lngs,
        lat: lats
      }
    },

    /**
     * 打开地图
     */
    openMap: function () {
      util.tapLog(3)
      uni.openLocation({
        latitude: this.lat,
        longitude: this.lng,
        success: function () {
          console.log('success');
        }
      });
    },

    /**
     * 生成二维码
     */
    getQrcode: function (stationCode) {
      this.stationQrCode = Qr.createQrCodeImg(stationCode)
    },

    // 查看提货凭证
    viewCertificate () {
      util.tapLog(3)
      var cont = {
        stationCode: this.stationCode, // 提货码
        stationAddress: this.stationAddress, // 自提点的地址
        stationPhone: this.stationPhone, // 自提点的联系电话
        stationTime: this.stationTime, // 自提时间(用户下单时选择)
        orderNumber: this.orderNumber, // 订单编号
        stationName: this.stationName
      }
      console.log('提货凭证con：', cont)
      uni.setStorageSync('stationCont', cont)
      uni.navigateTo({
        url: '/pages/delivery-certificate/delivery-certificate'
      })
    },

    toGroupDetails: function (e) {
      util.tapLog(3)
      uni.navigateTo({
        url: '/package-activities/pages/spell-group-details/spell-group-details?orderNumber=' + e.currentTarget.dataset.ordernumber
      });
    },
    // #ifdef  APP-PLUS
    /**
     * 一键复制事件
     */
    // 设置系统剪贴板的内容。
    copyBtn () {
      util.tapLog(3)
      // 除了h5以外都可用的复制方法
      uni.setClipboardData({
        data: this.orderNumber,
        success: function () {
          uni.showToast({
            title: this.i18n.copySucceeded,
            icon: 'none',
            duration: 1000
          })
        }
      });
    },
    // #endif
  }
};
</script>
<style scoped lang='scss'>
@import "./order-detail.css";
</style>
